


##########
##参数定义
##########

   ######几何空间参数#######   ##用于构造实体群组，不保存到群组词典
      stepWidth = 280.mm                                          #踏步宽
      stepHeight = 160.mm                                         #踏步高
      stepNum = 18.to_i                                           #踏步数
      platformTopLength = 1520.mm                                 #上平台长
      platformBottomLength = 400.mm                               #下平台长
      stairBoardHeight = 270.mm                                   #梯板高
      stairBoardWidth = 2450.mm                                   #梯板宽
   #

   #####名称、索引#######   ##用于检索构件，保存到词典

      name = 'DT6.68'                                             #构件名称
      #group.name= ''

   #

   #####空间位置参数#######   ##用于定位和移动构件，保存到词典

      o = [0,0,0]                                                 #原点
      v = [1,0,0]                                                 #向量

   #

   #####钢筋参数######

      fulNo1RFDim = 18.mm                                   #通长1号筋直径
      fulNo1RFGrade = 'CE'                                  #通长1号筋规格
      fulNo1RFInterval = 100.mm                             #通长1号筋间距

      fulNo2RFDim = 12.mm                                   #通长2号筋直径
      fulNo2RFGrade = 'CE'                                  #通长2号筋规格
      fulNo2RFInterval = 100.mm                             #通长2号筋间距

      distrNo3RFDim = 10.mm                                 #分布3号筋直径
      distrNo3RFGrade = 'CE'                                #分布3号筋规格
      distrNo3RFInterval = 150.mm                           #分布3号筋间距

      coverToRF = 20.mm                                     #钢筋保护层厚度
      laCo = 35.to_i                                        #锚固系数
      bendingDimCo = 4.to_i                                 #弯芯直径系数4倍钢筋直径

   #

   #####换算得到参数#######

      totalHeight = stairBoardHeight + stepHeight * stepNum                                #总高
      totalLength = platformTopLength + stepWidth * (stepNum - 1) + platformBottomLength   #总长

      slopeAngle = Math.atan(160.0/280.0)                                                  #楼梯起坡角

      ptfbpy = Math.tan(slopeAngle/2)*stairBoardHeight + platformBottomLength              #下平台下偏移点
      ptftpy = platformTopLength - Math.tan(slopeAngle/2)*stairBoardHeight                 #上平台下偏移点

      topDeduct = coverToRF + fulNo2RFDim + distrNo3RFDim + fulNo1RFDim/2                                                  #上部边界扣减
      foldExpend = (stairBoardHeight - topDeduct - coverToRF - fulNo1RFDim/2)/Math.tan(slopeAngle)                         #折板延伸
      foldExpend2 = (stairBoardHeight - topDeduct - coverToRF - fulNo1RFDim/2)/Math.sin(slopeAngle)                         #折板延伸2
   #   

#

################
##楼梯断面角点计算
################

   model = Sketchup.active_model
   entities = model.active_entities
   group = entities.add_group
   pts = []
   pts.push([0, 0, totalHeight])
   pts.push([platformTopLength, 0, totalHeight])

   i = 1

   while i < stepNum  do
      
      pts.push([platformTopLength + stepWidth * (i-1), 0, totalHeight - stepHeight * i])
      pts.push([platformTopLength + stepWidth * i, 0, totalHeight - stepHeight * i])
      i +=1

   end

   pts.push([platformTopLength + stepWidth * (stepNum - 1), 0, totalHeight - stepHeight * stepNum])
   pts.push([totalLength, 0, totalHeight - stepHeight * stepNum])


   pts.push([totalLength, 0, 0])


#

##############
##1/2正切偏移值
##############
   ptfbpy = Math.tan(Math.atan(160.0/280.0)/2)*stairBoardHeight + platformBottomLength
   ptftpy = platformTopLength - Math.tan(Math.atan(160.0/280.0)/2)*stairBoardHeight

   pts.push([totalLength - ptfbpy, 0, 0])
   pts.push([ptftpy - stepWidth, 0, totalHeight - stairBoardHeight])

   #pts.push([platformTopLength, 0, 0])
   pts.push([0, 0, totalHeight - stairBoardHeight])


   face = group.entities.add_face(pts)
   face.reverse!

   face.pushpull(stairBoardWidth, true)

#


####################
##面积与体积工程量提取
####################


   areaXs = 1550.0031000062013     #面积系数
   volumeXs = 61023.744094732334   #体积系数

   puts 'volume = '
   puts group.volume/volumeXs

   group.entities.each{|e|

      if e.class == Sketchup::Face
         puts e.area/areaXs
         puts e.normal
      end
   }


#


####################
##定义主edge轴线
####################

   group.entities.each{|e|

      if e.class == Sketchup::Edge
         #puts e.start.position.z
         if e.start.position.z == totalHeight && e.start.position.x == 0 && e.start.position.y == 0 && e.end.position.x == platformTopLength
            group.set_attribute "mainEdge", "id", e.entityID
            puts e.line
         end
      end
   }

   a = group.attribute_dictionary "mainEdge"
   a['id']
   #group.set_attribute "mainEdge", "id", 115
   
   ##需要两根相交直线向量，才能定位一个空间实体。


#


##########################
##配筋断面角点计算并生成face
##########################

   model = Sketchup.active_model
   entities = model.active_entities
   group = entities.add_group
   pts = []
   pts.push([0, 0, totalHeight])
   pts.push([platformTopLength - stepWidth, 0, totalHeight])
   pts.push([totalLength - platformBottomLength, 0, stairBoardHeight])
   pts.push([totalLength, 0, stairBoardHeight])
   pts.push([totalLength, 0, 0])




   pts.push([totalLength - ptfbpy, 0, 0])
   pts.push([ptftpy - stepWidth, 0, totalHeight - stairBoardHeight])

   #pts.push([platformTopLength, 0, 0])
   pts.push([0, 0, totalHeight - stairBoardHeight])


   face = group.entities.add_face(pts)

#

##########################
##1号筋角点计算并生成edge
##########################

   model = Sketchup.active_model
   entities = model.active_entities
   group = entities.add_group
   pts = []
   
   #####生成第一第二点#####
   p1stAxisZ = totalHeight - stairBoardHeight + coverToRF + fulNo1RFDim/2                                               #定义第一点的z坐标
   p2ndAxisX = platformTopLength - stepWidth - Math.tan(slopeAngle/2)*(stairBoardHeight - coverToRF - fulNo1RFDim/2)    #定义第二点的x坐标

   pts.push([coverToRF, 0, p1stAxisZ])         #第一点压栈
   pts.push([p2ndAxisX, 0, p1stAxisZ])         #第二点压栈   
   
   


   p3rdAxisX = platformTopLength - stepWidth - Math.tan(slopeAngle/2)*topDeduct + foldExpend                            #预定义第三点的x坐标


   
   #####判断是否满足直锚#####
   laLength = laCo * fulNo1RFDim        #计算1号筋的锚固长度
   if p3rdAxisX - p2ndAxisX > laLength - 50.mm 
      pts.push([p2ndAxisX + laLength, 0, p1stAxisZ]) 
      edge = group.entities.add_line(pts)  
   else
      arcDeduct = (bendingDimCo+1)*fulNo1RFDim/2            
      pts.push([p3rdAxisX - Math.tan(slopeAngle/2)*arcDeduct, 0, p1stAxisZ]) 
      group.entities.add_line(pts)
      arcedge = group.entities.add_arc([p3rdAxisX - Math.tan(slopeAngle/2)*arcDeduct, 0, p1stAxisZ - arcDeduct],
                                  [0,0,1], [0,1,0], arcDeduct, 0.degrees, slopeAngle)

      foldLength = laLength + p2ndAxisX - p3rdAxisX
      edge = group.entities.add_line(arcedge.last.end.position,
         [p3rdAxisX + foldLength*Math.cos(slopeAngle), 0, p1stAxisZ - foldLength*Math.sin(slopeAngle)])
      
      #pts.push([p3rdAxisX + foldLength*Math.cos(slopeAngle), 0, p1stAxisZ - foldLength*Math.sin(slopeAngle)])
   end

   ######路径跟踪绘制钢筋########
   
   
   face = group.entities.add_face(group.entities.add_circle [coverToRF, 0, p1stAxisZ],[1,0,0],fulNo1RFDim/2)
   face.reverse!
   face.followme(edge.all_connected)
   
   

#


##########################
##2号筋角点计算并生成edge
##########################

   model = Sketchup.active_model
   entities = model.active_entities
   group = entities.add_group
   pts = []

   #####生成第一第二点#####
   p1stAxisZ = coverToRF + fulNo1RFDim/2                                                   #定义第一点的z坐标
   p1stAxisX = totalLength - coverToRF                                                     #定义第一点的x坐标
   p2ndAxisX = totalLength - ptfbpy + Math.tan(slopeAngle/2)*(coverToRF + fulNo1RFDim/2)                 #定义第二点的x坐标

   p3rdAxisZ = totalHeight - stairBoardHeight + coverToRF + fulNo1RFDim/2                                               #定义第三点的z坐标
   p3rdAxisX = platformTopLength - stepWidth - Math.tan(slopeAngle/2)*(stairBoardHeight - coverToRF - fulNo1RFDim/2)    #定义第三点的x坐标   
   
   pts.push([p1stAxisX, 0, p1stAxisZ])         #第一点压栈
   pts.push([p2ndAxisX, 0, p1stAxisZ])         #第二点压栈  
   pts.push([p3rdAxisX, 0, p3rdAxisZ])         #第三点压栈  


   #group.entities.add_line(pts)

   #####判断是否满足直锚#####
   laLength = laCo * fulNo1RFDim        #计算1号筋的锚固长度
   if foldExpend2 > laLength - 50.mm 
      pts.push([p3rdAxisX - laLength*Math.cos(slopeAngle), 0, p3rdAxisZ + laLength*Math.sin(slopeAngle)]) 
      edge = group.entities.add_line(pts)  
   else
      #pt3_4Length = foldExpend2*Math.cos(slopeAngle/2)*Math.cos(slopeAngle/2)
      arcDeduct = (bendingDimCo+1)*fulNo1RFDim/2
      p4thAxisX = p3rdAxisX - foldExpend2*Math.cos(slopeAngle)
      p4thAxisZ = p3rdAxisZ + foldExpend2*Math.sin(slopeAngle)
      pts.push([p4thAxisX, 0, p4thAxisZ])         #第四点压栈 
      pts.push([p4thAxisX - laLength + foldExpend2, 0, p4thAxisZ])         #第五点压栈 
      edge = group.entities.add_line(pts) 
      arcedge = group.entities.add_arc([p4thAxisX - Math.tan(slopeAngle/2)*arcDeduct, 0, p4thAxisZ - arcDeduct],
                                 [0,0,1], [0,1,0], arcDeduct, 0.degrees, slopeAngle)




      #edge = group.entities.add_line(arcedge.last.end.position,
         #[p3rdAxisX + foldLength*Math.cos(slopeAngle), 0, p1stAxisZ - foldLength*Math.sin(slopeAngle)])
      #foldLength = laLength + p2ndAxisX - p3rdAxisX
      #pts.push([p3rdAxisX + foldLength*Math.cos(slopeAngle), 0, p1stAxisZ - foldLength*Math.sin(slopeAngle)])
   end


   ######路径跟踪绘制钢筋########
   
   
   face = group.entities.add_face(group.entities.add_circle [coverToRF, 0, p1stAxisZ],[1,0,0],fulNo1RFDim/2)
   face.reverse!
   face.followme(edge.all_connected)
   
   
#


